package notify

import (
	"fmt"
	"gitee.com/lllgo/gopkg/notify"
	"gitee.com/lllgo/opsctl/pkg/cmd"
	"gitee.com/lllgo/opsctl/pkg/conf"
	"github.com/mitchellh/mapstructure"
)

type Config struct {
	Email notify.EmailConfig
}

func init() {
	cmd.RegisterCmdPlugin("notify", func(pc conf.PluginConfig, c conf.ComponentConfig) error {
		var cfg Config
		if err := mapstructure.Decode(c, &cfg); err != nil {
			return err
		}

		if cfg.Email.User != "" {
			return cfg.Email.Notify()
		}
		fmt.Println("不需要通知")
		return nil
	}, conf.PluginConfig{
		Desc:     "通知功能，支持邮件发送",
		Cmd:      "notify",
		Register: "register.yaml",
	})

}
